/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class ResultTestName extends BaseDAO {

    private Connection con = getConnection();
    private ResultSet rs;
    private Statement stmt = null;
    private PreparedStatement pStmt = null;

    public ResultSet viewResult() {
        try {
            stmt = con.createStatement();
            rs = stmt.executeQuery("SELECT DISTINCT M.USERNAME ,M.STATUS,M.FULLNAME FROM MEMBERS M,RESULT R WHERE M.USERNAME = R.USERNAME");

        } catch (SQLException ex) {
            Logger.getLogger(ResultTestName.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rs;
    }

    public ResultSet viewResultTest() {
        try {
            stmt = con.createStatement();
            rs = stmt.executeQuery("SELECT * FROM MEMBERS M,RESULT R WHERE M.USERNAME = R.USERNAME");

        } catch (SQLException ex) {
            Logger.getLogger(ResultTestName.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rs;
    }
    public ResultSet viewResultTestName(String n) {
        try {
           pStmt = con.prepareCall("SELECT * FROM RESULT R,TEST T WHERE T.TESTID = R.TESTID AND R.USERNAME = ?");
           pStmt.setString(1, n);
           rs = pStmt.executeQuery();
        } catch (SQLException ex) {
            Logger.getLogger(ResultTestName.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rs;
    }
    public int viewResultTestCount(String n) {
        int number =0;
        try {
           pStmt = con.prepareCall("SELECT * FROM RESULT R,TEST T WHERE T.TESTID = R.TESTID AND R.USERNAME = ?");
           pStmt.setString(1, n);
           rs = pStmt.executeQuery();
           while(rs.next()) {
               number++;
           }
        } catch (SQLException ex) {
            Logger.getLogger(ResultTestName.class.getName()).log(Level.SEVERE, null, ex);
        }
        return number;
    }
}
